package ch8.Swim;
//潜艇
public class Submarine implements Swim,Sonar {
    private String name;
    private double weight;

    public Submarine(String name, double weight) {
        this.name = name;
        this.weight = weight;
    }

    @Override
    public Swim scan(Swim s) {
        System.out.println(this.getName()+"通过声呐扫描到了"+s);
        if(s instanceof Submarine){
            System.out.println("发射鱼雷，炸毁它。");
            return s;
        } else if (s instanceof Fish) {
            System.out.println("不管它，让它继续游泳。");
            return s;
        }
        return null;
    }

    @Override
    public void swim() {
        System.out.println("他正在深海游泳作业。");
    }

    @Override
    public String toString() {
        return "这艘潜艇的名字是：" + name +
                ",重量是：" + weight+"吨。" ;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }
}
